package com.pai4j.pgc.dao.community;
import com.pai4j.pgc.entity.community.CCNavEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 *
 * @author: CYM-pai
 * @date: 2025/10/27 14:37
 **/
@Repository
public interface ICCNavDAO extends JpaSpecificationExecutor<CCNavEntity>, JpaRepository<CCNavEntity, Long> {

    CCNavEntity findAllById(Long id);

    @Query(value = "select nav from CCNavEntity nav where nav.pathId in " +
            "(select p.id from CCNavPathEntity p where p.ccId = :ccId) and nav.status = :status " +
            "order by nav.score desc, nav.id desc")
    List<CCNavEntity> queryCTCNavList(Long ccId, String status);


    @Query(value = "select nav.* from pai4j_nav nav where " +
            "nav.path_id in (select p.id from pai4j_nav_path p where p.cc_id = :ccId) and nav.status = 'PUBLISHED' " +
            "order by nav.score desc, nav.id desc limit :size",
            nativeQuery = true)
    List<CCNavEntity> queryCTCRecommendNavList(Long ccId, int size);
}
